package edu.gatech.coc.sirana.detection;

import java.util.ArrayList;

public class AttributeCluster {
	private SRCycleAttribute center;
	private ArrayList<SRCycleAttribute> elements = new ArrayList<SRCycleAttribute>();
	private int isKnownFailure;
	
	public AttributeCluster(int is){
		this.setKnownFailure(is);
	}
	
	public boolean containElement(SRCycleAttribute src){
		return this.elements.contains(src);
	}
		
	public SRCycleAttribute getCenter() {
		return center;
	}

	public boolean isCenter(SRCycleAttribute src){
		return this.center.getId() == src.getId();
	}
	
	public void setCenter(SRCycleAttribute center) {
		this.center = center;
	}

	public int getIsKnownFailure() {
		return isKnownFailure;
	}

	public void setIsKnownFailure(int isKnownFailure) {
		this.isKnownFailure = isKnownFailure;
	}

	public void addElement(SRCycleAttribute src){
		this.getElements().add(src);
	}
	
	public ArrayList<SRCycleAttribute> getAllElements(){
		ArrayList<SRCycleAttribute> allEs = getElements();
		allEs.add(center);
		
		return allEs;
	}
	
	public ArrayList<SRCycleAttribute> getElements() {
		return elements;
	}

	public void setElements(ArrayList<SRCycleAttribute> elements) {
		this.elements = elements;
	}
		
	public int isKnownFailure() {
		return isKnownFailure;
	}

	public void setKnownFailure(int isFailure) {		
		this.isKnownFailure = isFailure;
	}

	public String toString(){
		StringBuffer sb = new StringBuffer( "Cluster: status=" + isKnownFailure ) ;
		sb.append( ";\tcenter: " + center.toString() + ";\telements:" + elements.size() );
		for (SRCycleAttribute e: elements){
			sb.append( " \n\t{" + e.toString() + " }; ");
		}

		return sb.toString();//.substring(0, sb.length()-1);
	}
}
